/**
 * @file    ModemEvents.h
 * @brief   Collects events (wosh::Fact extension) related to Modem devices.
 *
 * @see     wosh::devices::Modem_ConnectionChanged [wosh::interfaces::devices::Modem]
 ****************************************************************************
 * @version 0.8.462 $Id: ModemEvents.h 2891 2010-08-12 01:58:59Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Interfaces_Events_Modem_H__
 #define __WOSH_Interfaces_Events_Modem_H__

 #include <woshDefs.h>
 #include <core/Fact.h>
 #include <interfaces/devices/Modem.h>

 
namespace wosh {
 namespace devices {

 #define _Modem_EVENT_ConnectionChanged		"ConnectionChanged"

/**
 * @class   wosh::devices::Modem_ConnectionChanged
 * @brief   Raised when connection state has been changed.
 *
 * Internally data is stored as a Variant[INT] (when previous state is not
 * available) or a List containing two Variant[INT] (second value stores
 * the previous connection state). 
 *
 * There are no additional fields, this is a wrapper class provided for convenience.
 *
 * @see     wosh::Fact
 * @see     wosh::interfaces::devices::Modem
 ****************************************************************************
 * @version 0.8.462 $Id: ModemEvents.h 2891 2010-08-12 01:58:59Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
class Modem_ConnectionChanged : public wosh::Fact
 {
	WOSH_SERIALIZABLE(wosh::devices::Modem_ConnectionChanged)

	public:
		/**
		 * @brief  Empty constructor.
		 */
		Modem_ConnectionChanged()
			: wosh::Fact(_Modem_EVENT_ConnectionChanged) { }
		/**
		 * @brief  Constructor with initializers.
		 * @param connection_state [in] the new state of the connection
		 */
		Modem_ConnectionChanged( wosh::interfaces::devices::Modem::CONNECTION_STATE connection_state );
		/**
		 * @brief  Constructor with initializers.
		 * @param connection_state [in] the new state of the connection
		 * @param previous_connection_state [in] the old (previous) state of the connection
		 */
		Modem_ConnectionChanged( wosh::interfaces::devices::Modem::CONNECTION_STATE connection_state,
								 wosh::interfaces::devices::Modem::CONNECTION_STATE previous_connection_state );
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		Modem_ConnectionChanged( const Modem_ConnectionChanged& m )
			: wosh::Fact(m) { }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~Modem_ConnectionChanged() { }

	public:
		/**
		 * @brief   Get the new connection state.
		 * @return  integer value defined in wosh::interfaces::devices::Modem::CONNECTION_STATE
		 */
		wosh::interfaces::devices::Modem::CONNECTION_STATE getConnectionState() const;

		inline bool isConnected() const			{ return ( (getConnectionState() & wosh::interfaces::devices::Modem::STATE_CONNECTED) == wosh::interfaces::devices::Modem::STATE_CONNECTED ); }
		inline bool isDisconnected() const		{ return ( (getConnectionState() & wosh::interfaces::devices::Modem::STATE_DISCONNECTED) == wosh::interfaces::devices::Modem::STATE_DISCONNECTED ); }

		/**
		 * @brief   Get connection state as a literal string
		 * @return  connection state as literal string
		 */
		inline const char* getConnectionStateAsString() const {
			return wosh::interfaces::devices::Modem::getConnectionStateAsString( getConnectionState() );
		 }

		/**
		 * @brief   Get the previous connection state.
		 * @return  integer value defined in wosh::interfaces::devices::Modem::CONNECTION_STATE
		 */
		wosh::interfaces::devices::Modem::CONNECTION_STATE getPreviousConnectionState() const;

	public:
		/**
		 * @brief   Get a human friendly description of the event
		 * @return  string such as "Modem is Connected"
		 */
		virtual std::string toString() const;


}; // class def


 }; // namespace devices
}; // namespace wosh


#endif //__WOSH_Interfaces_Events_Modem_H__
